package com.campus.common.result;

import com.campus.common.enumUtil.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public Result() {}

    public static <T> Result<T> build(T data){
        Result<T> result = new Result<>();
        if (data != null) {
            result.setData(data);
        }
        return result;
    }

    public static <T> Result<T> build(T body,Integer code,String message ){
        Result<T> result = build(body);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> build(T body,String message){
        Result<T> result=build(body);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> build(T body, ResultCodeEnum resultCodeEnum){
        Result<T> result=build(body);
        result.setCode(resultCodeEnum.getCode());
        result.setMessage(resultCodeEnum.getMessage());
        return result;
    }

    public static <T> Result<T> fail(T body){
        Result<T> result=build(body,ResultCodeEnum.ERROR);
        return result;
    }

    public static <T> Result<T> fail(T body,String message){
        return build(body,message);
    }

    public static <T> Result<T> success(T body){
        return build(body, ResultCodeEnum.SUCCESS);
    }

    public static <T> Result<T> success()
    {
        return build(null, ResultCodeEnum.SUCCESS);
    }

    public static <T> Result<T> success(T body,String message){
        return build(body,message);
    }

}
